using System;

namespace VCDepend.Engine.DependencySources
{
	public class SolutionDependencySource : IDependencySource
	{
		Solution m_solution;
		ProjectStore m_projects;

		public SolutionDependencySource(Solution solution, ProjectStore projects)
		{
			m_solution = solution;
			m_projects = projects;
		}

		// IDependencySource implementation
		public string[] GetDependencyNames(Project project)
		{
			string[] dependencies = m_solution.GetDependencyGuids(project.Id);

			for (int i = 0; i < dependencies.Length; ++i)
			{
				dependencies[i] = ResolveFriendlyName(dependencies[i]);
			}

			return dependencies;
		}

		private string ResolveFriendlyName(string projectGuid)
		{
			Project project = m_projects.GetById(projectGuid);
			if (project == null)
				return projectGuid;

			return project.Name;
		}
	}
}
